package com.harboursoftware.xstorage.unit.mock

import java.util.List;
import com.harboursoftware.xstorage.model.XUser;
import com.harboursoftware.xstorage.XStorageException;
import com.harboursoftware.xstorage.db.BucketDao;
import com.harboursoftware.xstorage.model.XBucket;

class MockBucketDao implements BucketDao {
    Map bucketMap = [:]
    
    @Override
    public void deleteBucket(XBucket bucket) throws XStorageException {
        if(!bucketMap.containsKey(bucket.name)) {
            throw new XStorageException("bucket does not exists");
        }
        bucketMap.remove bucket.name
    }
    
    @Override
    public XBucket findBucketByName(String name) throws XStorageException {
        bucketMap.get name
    }
    
    @Override
    public void saveBucket(XBucket bucket) throws XStorageException {
        if(bucketMap.containsKey(bucket.name)) {
            throw new XStorageException("bucket already exists");
        }
        bucketMap.put bucket.name, bucket
    }
    
    @Override
    public void updateBucket(XBucket bucket) throws XStorageException {
        bucketMap.put bucket.name, bucket
    }
    
    @Override
    public List<XBucket> findBucketsOfUser(XUser user) throws XStorageException {
        //TODO 未完成
    }
}
